﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Output.ServiceReference1;
using System.Data.Services.Client;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;

namespace Output.View
{
    /// <summary>
    /// Interaction logic for OutputView.xaml
    /// </summary>
    /// 

    public partial class OutputView : UserControl, IActivityView
    {
        ServiceReference1.Container context = new ServiceReference1.Container(new Uri("http://localhost:1179/odata"));

        private ActivityPresenter presenter;
        private readonly IUnityContainer container;
        private readonly IRegionManager rManager;

        public OutputView(IUnityContainer c, IRegionManager r, ActivityPresenter presenter)
        {
            container = c;
            rManager = r;

            this.presenter = presenter;
            presenter.View = this;

            InitializeComponent();

            this.companiesDataGrid.DataContext = context.Companies;

            CollectionViewSource companiesViewSource = (CollectionViewSource)this.Resources["companiesViewSource"];
            companiesViewSource.Source = context.Companies;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string str = string.Format("\"{0}\"에 {1}박스 / {2}개를 출하합니다.", this.com_NameTextBox.Text, this.EaTextBox.Text, this.BoxTextBox.Text);
            if (MessageBox.Show(str, "출하 확인", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Uri viewNav = new Uri("EndingView", UriKind.Relative);
                rManager.RequestNavigate(RegionNames.MainContentRegion, viewNav);
            }
            
            else
            {
                MessageBox.Show("다시 입력해주세요.", "재입력");
            }
                
        }

        public void SetLotNumber(string number)
        {
            this.Lottext.Text = number;           
        }

        public void SetPmId(string number2)
        {
            var context2 = from kkk in context.Product_Mid
                           where kkk.PM_LotNumber == this.Lottext.Text
                           where kkk.PM_Id == Convert.ToInt32(number2)
                           select kkk;

            this.product_MidDataGrid.DataContext = context2;

            CollectionViewSource product_MidViewSource = (CollectionViewSource)this.Resources["product_MidViewSource"];
            product_MidViewSource.Source = context2;
        }

        public void SetNumber(string number3)
        {
            this.EaTextBox.Text = number3;
        }
    }
}
